﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;


// Additional Libraries
using System.Security.Cryptography;
using System.Text;
using Microsoft.Phone.Shell;
using LocalDatabase.Model;
using Microsoft.Phone.Controls;
using System.Windows.Navigation;
using System.IO.IsolatedStorage;

namespace FindMe
{
     public partial class MessageBoxSaveHome : UserControl
    {

         IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
           
         public MessageBoxSaveHome()
        {
            InitializeComponent();
            if (settings.Contains("HomeLocation") || (App.UserHomeLocation != string.Empty))
            {
                Description.Text = "There's an old saved home location." + Environment.NewLine + "Set this location as your new home?";
            }
            else
            {
                Description.Text = "There's no home location found." + Environment.NewLine + "Set this location as your home?";
            }
        }


        private void AddBtn_Click(object sender, RoutedEventArgs e)
        {          
            
            //Adds a new HomeLocation and deletes old
            if (!settings.Contains("HomeLocation"))
            {            
                settings.Add("HomeLocation", App.UserCoordinates);
                App.UserHomeLocation = (settings["HomeLocation"]).ToString();
            }
            else
            {
                settings["HomeLocation"] = App.UserCoordinates;
                App.UserHomeLocation = (settings["HomeLocation"]).ToString();
            }
            settings.Save();    
            ClosePopup();
                MessageBox.Show("Home Location Saved!");    
            //(Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri(App.PathFavLocations, UriKind.Relative));
        }       

    

        private void CancelBtn_Click(object sender, RoutedEventArgs e)
        {
            ClosePopup();
        }

        private void ClosePopup()
        {
            App.popUpNewLocation = 0;
            Popup Pop = this.Parent as Popup;
            Pop.IsOpen = false;                       
        }

   }
}
